#! /bin/sh

#可执行文件名称
jarname=test
mainCls=test.main.App
jvmopts="-Xms512m -Xmx512m"

#运行日志文件
chmod +x -R *
apphome=`pwd`
logdir=$apphome/logs
logfile=$apphome/logs/log.log
jarfile=$jarname.jar
classpath=./conf:./lib/*:$jarfile

#log file
if [ -d $logdir ]; then
  echo " "
else
  mkdir $logdir
fi

if [ -f $logfile ]; then
  echo " "
else
  touch $logfile
fi

#可执行权限
chmod +x -R *

#开始启动
start(){
  echo "app is start running ..." 
  exec java $jvmopts  -cp $classpath $mainCls 5 > logs/log.log
}

#停止运行
stop(){
  ps -ef|grep $jarname|grep -v grep|awk '{print $2}'|while read pid
  do
    kill -9 $pid
  done
  echo "app is stop "
}

#执行配置
case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
restart)
  stop
  start
  ;;
*)
  printf 'Use cmd append shell: %s {start|stop|restart}\n' "$prog"
  exit 1
  ;;
esac
